<template>
	<view
	    class="c-radio-group"
	>
		<slot></slot>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				disabled: false
			}
		},
		props: {
			// 绑定的值
			value: {
			    type: Object,
			    default: () => {}
			},
		},
		mounted() {
			this.$nextTick(() => {
				setTimeout(() => {
					let children = null;
					// #ifdef APP-PLUS
					children = this.$children;
					// #endif
					// #ifdef H5
					children = this.$children[0].$children;
					// #endif
					if(!children) return;
					children.forEach(item => {
						if(this.value && item.name == this.value.label) {
							item.checked = true;
						}
						if(item.name == '其他') item.value = this.value.value;
					})
				},100)
			})
		},
		methods: {
			// 将其他的radio设置为未选中的状态
			radioGroupChange(childInstance) {
				const {
					name,value
				} = childInstance
				// 通过emit事件，设置父组件通过v-model双向绑定的值
				this.$emit('input', {
					label: name,
					value
				})
				// 发出事件
				this.$emit('change', name)
			},
			valueChange(childInstance) {
				const {
					name,value
				} = childInstance
				this.$emit('input', {
					label: name,
					value
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.c-radio-group {
		flex: 1;
	}
</style>
